<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input
          v-model="query.tradeNo"
          clearable
          placeholder="支付单号"
          style="width: 185px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="query.outTradeNo"
          clearable
          placeholder="外部支付单号"
          style="width: 185px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="query.orderSn"
          clearable
          placeholder="订单号"
          style="width: 185px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-select
          v-model="query.payType"
          filterable
          placeholder="请选择支付方式"
          style="width: 185px;"
          class="filter-item"
          clearable
        >
          <el-option
            v-for="item in dict.payType"
            :key="item.id"
            :label="item.dictValue"
            :value="item.dictKey"
          />
        </el-select>
        <date-range-picker
          v-model="modelCreateTime"
          start-placeholder="创建时间"
          end-placeholder="作废时间"
          :fix-date.sync="query.createTime"
          class="date-item"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="800px"
      >
        <el-form ref="form" :model="form" :rules="rules" label-width="100px" />
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        stripe
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="单号" />
        <el-table-column prop="outTradeNo" label="外部单号" width="200"/>
        <el-table-column prop="orderSn" label="订单号" />
        <el-table-column prop="memberName" label="会员名称" />
        <el-table-column prop="payType" label="支付方式">
          <template slot-scope="scope">
            {{ dict.label.payType[scope.row.payType] }}
          </template>
        </el-table-column>
        <el-table-column prop="payAmount" label="金额" align="right" />
        <el-table-column prop="tradeState" label="支付状态">
          <template slot-scope="scope">
            {{ dict.label.tradeState[scope.row.tradeState] }}
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="cancelTime" label="作废时间" />
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudTrade from '@/api/fms/trade'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker'

const defaultForm = {
  tradeNo: null,
  outTradeNo: null,
  orderSn: null,
  payType: null,
  payAmount: null,
  subject: null,
  body: null,
  tradeState: 0,
  createTime: null,
  cancelTime: null
}
export default {
  name: 'Trade',
  components: { pagination, crudOperation, rrOperation, DateRangePicker },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['tradeState', 'payType'],
  cruds() {
    return CRUD({
      title: '支付单', url: 'trade/page', sort: 'id:desc', crudMethod: { ...crudTrade }, optShow: {
        add: false,
        edit: false,
        del: true,
        download: true,
        reset: true
      }
    })
  },
  data() {
    return {
      modelCreateTime: '',
      permission: {
        add: ['admin', 'trade:add'],
        edit: ['admin', 'trade:edit'],
        del: ['admin', 'trade:del']
      },
      rules: {},
      queryTypeOptions: [
        { key: 'tradeNo', display_name: '支付单号' },
        { key: 'outTradeNo', display_name: '外部支付单号' },
        { key: 'orderSn', display_name: '订单号' },
        { key: 'payType', display_name: '支付方式' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
